import 'package:flutter/material.dart';
import 'package:flutter_card_plugin/flutter_card_plugin.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {


  String cardNumber="";
  bool status=false;
  @override
  void initState() {
    super.initState();
    FlutterCardPlugin.instance.slotCardCallBack = slotCardCallBack;///刷卡监听
  }



  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: [
              Text('卡号: $cardNumber'),

              GestureDetector(
                onTap:(){
                  devicRestart();
                },
                child: Container(
                  width: 80,
                  height: 50,
                  alignment: Alignment.center,
                  margin: const EdgeInsets.only(top: 10),
                  color: Colors.blue,
                  child: const Text('重启',style: TextStyle(color: Colors.white),),
                ),
              ),

              GestureDetector(
                onTap: (){
                  devicPowerOff();
                },
                child: Container(
                  width: 80,
                  height: 50,
                  margin: const EdgeInsets.only(top: 10),
                  alignment: Alignment.center,
                  color: Colors.blue,
                  child: const Text('关机',style: TextStyle(color: Colors.white),),
                ),
              ),

              GestureDetector(
                onTap: (){
                  settingStatusBar(true);
                },
              child:Container(
                width: 80,
                height: 50,
                margin: const EdgeInsets.only(top: 10),
                alignment: Alignment.center,
                color: Colors.blue,
                child: const Text('显示状态栏',style: TextStyle(color: Colors.white),),
              )
            ),
              GestureDetector(
              onTap: (){
                settingStatusBar(false);
              },
              child:Container(
                width: 80,
                height: 50,
                margin: const EdgeInsets.only(top: 10),
                alignment: Alignment.center,
                color: Colors.blue,
                child: const Text('隐藏状态栏',style: TextStyle(color: Colors.white),),
              )
              ),
            ],
          ),
        ),
      ),
    );
  }



  slotCardCallBack(CardValue cardValue) {
     cardNumber = cardValue.name ?? ""; //卡号
     setState(() {});
    print("卡号${cardNumber}");
  }



  ///设置状态栏显示和隐藏(true/false)
  Future settingStatusBar(bool status)async{
    FlutterCardPlugin.instance.showOrHideStatusBar(data: {"status":status});
  }


  ///电子班牌设备重启
  Future devicRestart()async{
    FlutterCardPlugin.instance.restart();
  }



  ///电子班牌关机
  Future devicPowerOff()async{
    FlutterCardPlugin.instance.powerOff();
  }

  ///静默安装应用
 Future installAPK()async{
   //path：apk安装路径，pkgname:应用包名com.zaedu.card
   String path="";//测试请输入包名和路径一定要正确否则无法生效
   String pkgname="com.zaedu.card";//apk包名
   FlutterCardPlugin.instance.installAPK(data: {"path":path,"pkgname":pragma});
 }



}
